module mQSort

        use mPrecision

        implicit none

        interface smallestToLargest
#ifdef UNTESTED
                module procedure smallestToLargest_i4
#endif ! UNTESTED
                module procedure smallestToLargest_D
        end interface smallestToLargest

        private
        public :: smallestToLargest

contains

#ifdef UNTESTED
        subroutine smallestToLargest_i4(array)

                use ifport
                use mMisc

                integer(4), intent(in) :: array(:)

                integer(4) :: arraySize, count

                write(0, *) 'ERROR: smallestToLarges_i4t untested'
                stop

!                call qsort(array, size(array), D, difference)
                arraySize = int( size(array), 4 )
                count = arraySize
                call sortqq( loc(array), count, SRT$INTEGER4 )

                call assert( count == arraySize, 'smallestToLargest sort failed' )

        end subroutine smallestToLargest_i4
#endif ! UNTESTED

        subroutine smallestToLargest_D(array)

#ifdef IFORT
                use ifport
!#else if( defined(PGF90) )
!                interface
!                        subroutine qsort(array, len, isize, compar)
!                                integer :: isize
!                                real(isize) :: array(*)
!                                integer :: len
!                                interface
!                                        integer function compare(a, b)
!                                                real(isize) :: a, b
!                                        end function compare
!                                end interface
!                        end subroutine qsort
!                end interface
#endif ! PGF90

                real(D), intent(in) :: array(:)
                call qsort(array, size(array), D, difference)

        end subroutine smallestToLargest_D

        integer(2) function difference(a, b)

                real(D), intent(in) :: a, b

                difference = int(a - b, 2)

        end function difference

        subroutine removeDups(array)

                integer, intent(in) :: array

                integer i

                i = 1
!                do while(i < size(array))

!                     if( array(i) == array(i - 1)   

        end subroutine removeDups

end module mQSort
